import * as echarts from '../../ec-canvas/echarts';
var util = require('../../utils/util.js');
const app = getApp();

function initChart(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);



  var option = {
    backgroundColor: "#ffffff",
    color: ["#C9CACB", "#FADB03", "#FA2C2C"],
    series: [{
      label: {
        normal: {
          fontSize: 14
        }
      },
      type: 'pie',
      center: ['50%', '60%'],
      radius: [0, '60%'],
      data: [{
        value: 5,
        name: '白银'
      }, {
        value: 3,
        name: '黄金'
      }, {
        value: 1,
        name: '钻石'
      },
      ],
      itemStyle: {
        emphasis: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 2, 2, 0.3)'
        }
      }
    }]
  };

  chart.setOption(option);
  return chart;
}
var inputInfo = null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userlist:null,
    adapterSource: [],//本地匹配源
    bindSource: [],//绑定到页面的数据，根据用户输入动态变化
    ec: {
      onInit: initChart
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var aa = this;
    console.log("这里到了报备的onLoad");
    console.log(app.globalData.myInfo);
    util.https('listCall.shtml', "GET", { eid: app.globalData.myInfo.eid },
      aa.callback
    )
  }, callback: function (res) {
    var bb = this;
    console.log(res);
    console.log(res.data.length);
    if (res.code == 0) {
      console.log(res.data[0].cname);
      console.log(res.data[0].cphone);
      console.log(res.data[0].dictionary.dictdataValue);
      bb.setData({ userlist: res.data });

      var setInfo = new Array();
      for (var index in res.data) {
        setInfo[index] = res.data[index].cname;
        setInfo[res.data.length++] = res.data[index].cphone;
        console.log(res.data[index].cname + "--" + res.data[index].cphone);
      }
      console.log(setInfo);
      console.log(bb.data.adapterSource);
      bb.setData({
        adapterSource: setInfo
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return {
      title: 'ECharts 可以在微信小程序中使用啦！',
      path: '/pages/index/index',
      success: function () { },
      fail: function () { }
    }
  },// 点击事件触发page执行转发的函数
  onShareApp: function () {
    this.onShareAppMessage()
  },
  // 拨打电话
  bind_tal: function (event) {
      var $this = this;
      console.log(event.target.dataset)
    wx.makePhoneCall({
      phoneNumber: event.target.dataset.index//15071255813
    })
  },
  likSelect : function(){
    
  }, bindinput: function (e) {
    var prefix = e.detail.value//用户实时输入值
    var newSource = []//匹配的结果
    var newList= new Array();
    console.log(prefix);
    if (prefix != "") {
      var ab=this;
      console.log(newSource.length);
      util.https("selectLikeCustomerInfo.shtml", "POST", { likeInfo: prefix, eid: app.globalData.myInfo.eid},
      function(data){
        console.log(data.data);
        if (data.data != undefined){
        ab.setData({
          bindSource: data.data
        })
        }
      }
      );
    }else{
      
      this.setData({
        bindSource: ""
      })
    }
    }
    ,
  itemtap: function (e) {
    this.setData({
      inputValue: e.target.id,
      bindSource: []
    })
  }
})